using LiJ.Common.Core;
using LiJ.Http.Extention;
using LiJ.Http.Mos;
using System.Net.Http;
using System.Threading.Tasks;

namespace LiJ.Framework.Official
{
	/// <summary>
	///  基类
	/// </summary>
	public class WxBaseApi : BaseConfigProvider<AppConfig, WxBaseApi>
	{
		/// <summary>
		/// 微信api接口地址
		/// </summary>
		protected const string m_ApiUrl = "https://api.weixin.qq.com";

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="config"></param>
		public WxBaseApi(AppConfig config)
			: base(config)
		{
			base.ModuleName = WxOfficialConfigProvider.ModuleName;
		}

		/// <summary>
		/// 处理远程请求方法，并返回需要的实体
		/// </summary>
		/// <typeparam name="T">需要返回的实体类型</typeparam>
		/// <param name="request">远程请求组件的request基本信息</param>
		/// <param name="client">自定义HttpClient</param>
		/// <returns>实体类型</returns>
		public async Task<T> RestCommonJson<T>(LHttpRequest request, HttpClient client = null) where T : WxBaseResp, new()
		{
			T val = await LRestExtention.RestCommonJson<T>(request, client, "default");
			if (!val.IsSuccess())
			{
				val.Msg = val.Errmsg;
			}
			return val;
		}

		/// <inheritdoc />
		protected override AppConfig GetDefaultConfig()
		{
			return WxOfficialConfigProvider.DefaultConfig;
		}
	}
}
